import java.util.List;
import java.util.ArrayList;
import java.util.Scanner;
public class OrderMgr {

    private static ArrayList<Order> orderList=new ArrayList<Order>();

    private static ArrayList<Dish> dishList=new ArrayList<Dish>();

    private static Scanner input=new Scanner(System.in);

    public static void initData()
    {

        dishList.add(new Dish("红烧带鱼",38.00,1));
        dishList.add(new Dish("鱼香肉丝",20.00,1));
        dishList.add(new Dish("臭桂鱼",88.00,1));
        dishList.add(new Dish("水煮肉片",56.00,1));
        dishList.add(new Dish("红烧肉",70.00,1));
        dishList.add(new Dish("蚂蚁上树",20.00,1));
    }
    public static void startMenu()
    {
        Scanner input=new Scanner(System.in);
        boolean flag=true;
        int num=-1;
        System.out.println("\n欢迎使用吃货联盟订餐系统");

        do
        {
            System.out.println("****************************");
            System.out.println("1、我要订餐");
            System.out.println("2、查看餐袋");
            System.out.println("3、签收订单");
            System.out.println("4、删除订单");
            System.out.println("5、我要点赞");
            System.out.println("6、退出系统");
            System.out.println("****************************");
            System.out.print("请选择,请输入数字：");
            int choose = input.nextInt();
            flag=true;
            switch (choose) {
                case 1:

                    System.out.println("***我要订餐***");
                    orderFood();
                    break;
                case 2:

                    System.out.println("***查看订单***");
                    viewMealBags();
                    break;
                case 3:

                    System.out.println("***签收订单***");
                    signOrder();
                    break;
                case 4:

                    System.out.println("***删除订单***");
                    deleteOrder();
                    break;
                case 5:

                    System.out.println("***我要点赞***");
                    dianZan();
                    break;
                case 6:

                    System.out.println("***成功退出系统***");
                    flag = false;
                    System.out.println("谢谢使用本系统，欢迎下次光临！");
                    System.exit(0);
                    break;
                default:
                    flag = false;
                    break;
            }
            if (flag) {
                System.out.print("输入0返回主菜单：");
                num = input.nextInt();
            } else {
                break;
            }
        }while(num==0);
    }

    public static void dianZan()
    {
        System.out.println("序号\t菜名\t\t单价\t点赞数");
        for(int i=0;i<dishList.size();i++)
        {
            Dish dish=dishList.get(i);
            System.out.println((i+1)+"\t"+dish.getDishMeg()+"\t\t"+dish.getPrice()+"元"+"\t"+dish.getPraiseNum()+"赞");
            System.out.println("-----------------------------------------------------------");
        }
        System.out.print("请选择您要点赞的菜品序号：");
        int index=input.nextInt();
        index=index-1;
        if(index<0||index>=dishList.size())
        {
            System.out.println("您要点赞的菜品不存在");
        }
        else
        {
            dishList.get(index).setPraiseNum(dishList.get(index).getPraiseNum()+1);
            System.out.println("点赞成功！");
        }
    }

    public static void deleteOrder()
    {
        System.out.print("请输入要删除的订单序号：");
        int index=input.nextInt();
        index=index-1;
        if(index<0||index>=orderList.size())
        {
            System.out.println("你输入的订单信息不存在！");
        }
        else
        {
            if(orderList.get(index).getState()==1)
            {
                orderList.remove(index);
                System.out.println("订单删除成功！");
            }
            else
            {
                System.out.println("订单尚未签收！不能删除！");
            }
        }

    }

    public static void signOrder()
    {
        System.out.print("请选择要签收的订单的序号：");
        int index=input.nextInt();
        index=index-1;
        if(index<0||index>=orderList.size())
        {
            System.out.println("你输入的订单信息不存在！");

        }
        else
        {
            if(orderList.get(index).getState()==0)
            {
                orderList.get(index).setState(1);
                System.out.println("订单签收成功！");
            }
            else
            {
                System.out.println("您输入的订单已签收！");
            }
        }
    }

    public static void viewMealBags()
    {
        System.out.println("序号"+"\t"+"订餐人"+"\t"+"餐品信息"+"\t"+"\t"+"送餐时间"+"\t"+"送餐地址"+"\t"+"\t"+"总金额"+"\t"+"订单状态");
        for(int i=0;i<orderList.size();i++)
        {
            Order order=orderList.get(i);
            System.out.println((i+1)+"\t"+order.getName()+"\t"+order.getDishMeg()+"\t"+"\t"+order.getTime()+
                    "\t"+order.getAddress()+"\t"+"\t"+order.getTotalPrice()+"\t"+order.getState());
            System.out.println("-----------------------------------------------------------------------------");

        }
    }

    public static void orderFood()
    {
        System.out.print("请输入订餐人姓名：");
        String name=input.next();
        System.out.println("序号\t菜名\t\t单价\t点赞数");
        for(int i=0;i<dishList.size();i++)
        {
            Dish dish=dishList.get(i);
            System.out.println((i+1)+"\t"+dish.getDishMeg()+"\t\t"+dish.getPrice()+"元"+"\t"+dish.getPraiseNum()+"赞");
            System.out.println("-----------------------------------------------------------");
        }
        System.out.print("请选择您要点的菜品编号：");
        int index=input.nextInt();
        System.out.print("请选择您需要的份数：");
        int num=input.nextInt();
        String dishMeg=dishList.get(index-1).getDishMeg()+"-"+num+"份";
        double price=dishList.get(index-1).getPrice()*num;
        double addPrice=price>=50?0:5;
        double sumPrice=price+addPrice;
        int time;
        System.out.print("请输入送餐时间（送餐时间是10点至20点间整点送餐）：");
        time = input.nextInt();
        while(time<10||time>20)
        {
            System.out.print("您的输入有误，请重新输入（送餐时间是10点至20点间整点送餐）：");
            time=input.nextInt();
        }
        System.out.print("请输入送餐地址：");
        String address=input.next();

        Order order=new Order(name,dishMeg,time,address,0,sumPrice);
        orderList.add(order);
        System.out.println("订餐成功！");
        System.out.println("您订的是："+dishMeg);
        System.out.println("送餐时间："+time+"点");
        System.out.print("餐费："+price+"元,送餐费"+addPrice+"元，总计："+sumPrice+"元\n");
    }

    public static void main(String[] args) {

        initData();
        startMenu();

    }



}
